﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RayTracing
{
    class Triangle : Geometry
    {
        P3 p1, p2, p3;
        float depth;
        P2 pa, pb, pc;
        float infinity = 999999999999999999;

        public Triangle(P3 p1, P3 p2, P3 p3, float d) //3D triangles, triangles with depth!
        {
            this.p1 = p1;
            this.p2 = p2;
            this.p3 = p3;
            this.depth = d;
        }

        public Triangle(P2 p1, P2 p2, P2 p3) //2D triangles, a triangle shaped plane!
        {
            this.pa = p1;
            this.pb = p2;
            this.pc = p3;
        }

        //public bool intersect(Ray r) //are we intersecting the triangle? This is currently for P3's
        //{
        //    /* begin pseudo code */
        //    P3 b = vertex3 - vertex1;
        //    P3 c = vertex2 - vertex1;
        //    P3 Normal = P3.cross( c, b );
        //    float distance = -P3.dot( O - vertex1, N ) / P3.dot( D, N );

        //    // distance test
        //    if ((distance < epsilon) || (distance > max_distance)) return false;
        //    // determine dominant axis
        //    if (Math.Abs( N.x ) > Math.Abs( N.y ))
        //    {
        //      if (Math.Abs( N.x ) > Math.Abs( N.z )) axis = X;
        //      else axis = Z;
        //    }

        //    else
        //    {
        //      if (Math.Abs( N.y ) > Math.Abs( N.z )) axis = Y;
        //      else axis = Z;
        //    }
        //    // determine project plane axii
        //    Uaxis = (axis + 1) % 3;
        //    Vaxis = (axis + 2) % 3;
        //    // calculate hitpoint
        //    Pu = Ou + distance * Du;
        //    Pv = Ov + distance * Dv;
        //    // check intersection
        //    a2 = (bu * Pv - bv * Pu) / (bu * cv - bv * cu);

        //    if (a2 < 0) return false;
        //    a3 = (cv * Pu - cu * Pv) / (bu * cv - bv * cu);
        //    if (a3 < 0) return false;
        //    if (a2 + a3 > 1) return false;

        //    // ray intersects triangle
        //    return true;
        //    /* end pseudo code */
        //}

        float distance(Ray r) //this will come in handy... maybe
        {
            return infinity;
        }

        #region Geometry Members

        float Geometry.distance(Ray ray)
        {
            throw new NotImplementedException();
        }

        public P3 normal(P3 p)
        {
            throw new NotImplementedException();
        }

        public P2 toP2(P3 p)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region Geometry Members


        P3 Geometry.normal(P3 p)
        {
            throw new NotImplementedException();
        }

        P2 Geometry.toP2(P3 p)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
